//
//  ThemeDetailController.m
//  OnePiece
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "ThemeDetailController.h"
#import "UMSocial.h"
@interface ThemeDetailController ()<UIWebViewDelegate,UMSocialUIDelegate>

@end

@implementation ThemeDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleLable.text  = self.naviTitle;

    [self.leftButton setImage:[UIImage imageNamed:@"meishi-back"] forState:(UIControlStateNormal)];
    [self.leftButton addTarget:self action:@selector(back) forControlEvents:(UIControlEventTouchUpInside)];
    
    UIButton *shareButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    shareButton.frame = CGRectMake(SCREEN_WIDTH - 45, 15, 20, 20);
    [shareButton setImage:[UIImage imageNamed:@"meishi-share"] forState:(UIControlStateNormal)];
    [shareButton addTarget:self action:@selector(shareInfomation) forControlEvents:(UIControlEventTouchUpInside)];
    [self.topView addSubview:shareButton];
    
    
    UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-114)];
    
    NSString *htmlString = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.url]] encoding:NSUTF8StringEncoding];
    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"</div>" withString:@""];
    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"fixe-bar" withString:@""];
    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"我要回复" withString:@""];
    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"蜂蜂" withString:@""];
   
    
    [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:[NSBundle mainBundle].bundlePath]];
    
    webView.delegate = self;
    webView.scrollView.bounces = NO;
    [self.view addSubview:webView];
    
}

- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)shareInfomation{
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"562dcfa4e0f55a2a14004075"
                                      shareText:[NSString stringWithFormat:@"#旅游推荐地#%@",self.naviTitle]
                                     shareImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.img_url]]]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,nil]
                                       delegate:self];
    
}


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSString *str = [NSString stringWithFormat:@"%@",request.URL];
    if ([str rangeOfString:@"http"].location != NSNotFound) {
        return NO;
    }else{
        return YES;
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
